﻿namespace SenenFernandez.SmartExtensionMethods.Converter
{
    using System;
    using System.Globalization;
    using System.Windows;
    using System.Windows.Data;

    /// <summary>
    /// Visibility to Boolean Converter class.
    /// </summary>
    public class VisibilityToBoolConverter : IValueConverter
    {
        /// <summary>
        /// Converts <see cref="System.Windows.Visibility.Visible"/> to true and <see cref="System.Windows.Visibility.Collapsed"/> to false.
        /// </summary>
        /// <inheritdoc/>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (value != null && value is Visibility && targetType == typeof (bool))
                ? (Visibility) value == Visibility.Visible
                : value;
        }

        /// <summary>
        /// Converts true to <see cref="System.Windows.Visibility.Visible"/> and false to <see cref="System.Windows.Visibility.Collapsed"/>.
        /// </summary>
        /// <inheritdoc/>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Binding.DoNothing;
        }
    }
}